package com.example.mylibrary;

import android.widget.ImageView;

import androidx.annotation.IntegerRes;
import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.sunfusheng.GlideImageView;

public class ViewAdapter {
    /**
     * image
     *
     * @param view
     * @param url
     */
    @BindingAdapter(value = "imagesrc")
    public static void setImagesrc(ImageView view, String url) {
        ImageLoader.getInstance().loadImageUrl(view, url);
    }

    @BindingAdapter(value = "loadPic")
    public static void load(GlideImageView view, @IntegerRes int res) {
        view.loadDrawable(res);
    }


    /**
     * @param recyclerView
     * @param adapter
     */
    @BindingAdapter(value = "adapter")
    public static void setAdapter(RecyclerView recyclerView, RecyclerView.Adapter adapter) {
        recyclerView.setAdapter(adapter);
    }

    @BindingAdapter(value = "layoutmanager")
    public static void setLayoutManager(RecyclerView recyclerView, LayoutManagerFactory.RecyclerViewImpl impl) {
        if (impl.colume() != 0) {
            recyclerView.setLayoutManager(impl.createGridRv(recyclerView, impl.colume()));
        } else {
//            recyclerView.setLayoutManager(impl.createLinearRv(recyclerView,impl()));
        }

    }


}
